package com.jinghua.treatment.service.impl;

import com.jinghua.treatment.entity.SysInquirySubjectCategory;
import com.jinghua.treatment.entity.SysInquirySubjectCategoryItem;
import com.jinghua.treatment.entity.SysInquiryTemplate;
import com.jinghua.treatment.entity.SysInquiryTemplateExample;
import com.jinghua.treatment.mapper.SysInquirySubjectCategoryItemMapper;
import com.jinghua.treatment.mapper.SysInquirySubjectCategoryMapper;
import com.jinghua.treatment.mapper.SysInquiryTemplateMapper;
import com.jinghua.treatment.service.SysInquiryTemplateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 问诊单模板业务逻辑实现类
 * Created by 王兴光 on 2018/5/27.
 */
@Service()
public class SysInquiryTemplateServiceImpl implements SysInquiryTemplateService {
    @Resource
    private SysInquirySubjectCategoryMapper inquirySubjectCategoryMapper;
    @Resource
    private SysInquirySubjectCategoryItemMapper inquirySubjectCategoryItemMapper;
    @Resource
    private SysInquiryTemplateMapper inquiryTemplateMapper;
    @Override
    public List<SysInquirySubjectCategory> selectTemplateList(Integer templateId) {
        List<SysInquirySubjectCategory> templateList = new ArrayList<SysInquirySubjectCategory>();
        // 根据模板编号获取一级分类列表
        for (SysInquirySubjectCategory level1 : inquirySubjectCategoryMapper.selectLevel1ByTemplate(templateId)) {
            level1.setLevel2List(new ArrayList<SysInquirySubjectCategory>());
            // 根据一级分类编码获取二级分类列表
            for(SysInquirySubjectCategory level2 : inquirySubjectCategoryMapper.selectLevel2ByTemplate(level1.getCategoryCode())){
                level1.getLevel2List().add(level2); // 添加二级分类信息到一级分类信息的二级分类列表中
                level2.setLevel3List(new ArrayList<SysInquirySubjectCategoryItem>());
                // 根据二级分类编码获取三级分类列表
                for(SysInquirySubjectCategoryItem level3 : inquirySubjectCategoryItemMapper.selectLevel3ByTamplate(level2.getCategoryCode())){
                    level2.getLevel3List().add(level3); // 添加三级分类信息到二级分类信息的三级分类列表中
                }
            }
            templateList.add(level1);           // 添加一级分类信息到问诊单模板
        }
        return templateList;
    }

    @Override
    public List<SysInquiryTemplate> selectTemplateList() {
        return inquiryTemplateMapper.selectByExample(new SysInquiryTemplateExample());
    }
}
